<html>
<head><meta charset="utf-8"><title>Error context, with_context, and common contexts · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html">Error context, with_context, and common contexts</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="192730713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192730713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192730713">(Apr 02 2020 at 21:42)</a>:</h4>
<p>I've repeatedly found, when using <code>anyhow</code> in a large project, that I really want the <em>same</em> generated context across various uses of <code>?</code>, and I found it painful to repeatedly write things like <code>.with_context(|| format!("thing {} detail {}", thing, detail))?</code>.  To the point that in some cases I found myself writing <code>let context = || format!("thing {} detail {}", thing, detail);</code> at the top of a function and repeatedly using <code>.with_context(context)?</code>, which then led me to forget what was in the context and almost use the wrong context for an error. I also find myself only using it on errors that "need" context to make sense, when I really want it on most errors.</p>



<a name="192730730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192730730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192730730">(Apr 02 2020 at 21:43)</a>:</h4>
<p>I know that some error-handling libraries have experimented with having function-level contexts.</p>



<a name="192730876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192730876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192730876">(Apr 02 2020 at 21:44)</a>:</h4>
<p>I find myself wishing for a kind of "context block", or some kind of similar information, that lets me say "all errors in this block are related to X", and "all errors in this inner block are also related to Y", and have that automatically result in <code>.with_context</code> calls or similar, ideally with no overhead when <em>not</em> generating an error.</p>



<a name="192731325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192731325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192731325">(Apr 02 2020 at 21:48)</a>:</h4>
<p>I don't know what the language construct would look like to support that. I'm <em>tempted</em> to say that a combination of <code>try</code> and a macro might get part of the way there.</p>



<a name="192731398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192731398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192731398">(Apr 02 2020 at 21:49)</a>:</h4>
<p>I could, for instance, imagine something like <code>error_context!(|| format!("thing {} detail {}", thing, detail)) { ... }</code></p>



<a name="192731494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192731494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192731494">(Apr 02 2020 at 21:50)</a>:</h4>
<p>But I also, slightly, wonder if it'd be a <em>terrible</em> idea to support some kind of "please wrap the remainder of my current block in this macro without making me nest braces around it" mechanism.</p>



<a name="192731517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192731517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192731517">(Apr 02 2020 at 21:50)</a>:</h4>
<p>(That would also likely produce better results with <code>rustfmt</code>.)</p>



<a name="192731970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192731970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192731970">(Apr 02 2020 at 21:55)</a>:</h4>
<p>I also feel like "context" and "backtrace" are a little conflated. What I'm providing isn't another error, it's context for the error that's already happening.</p>



<a name="192732024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192732024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192732024">(Apr 02 2020 at 21:55)</a>:</h4>
<p>I think there's a semantic difference between "Error X happened while I was doing Y" and "Error Y happened, the underlying error is X but you may not care about that".</p>



<a name="192733912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192733912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192733912">(Apr 02 2020 at 22:13)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="220273">@Jane Lusby</span></p>



<a name="192734306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192734306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192734306">(Apr 02 2020 at 22:17)</a>:</h4>
<blockquote>
<p>I also feel like "context" and "backtrace" are a little conflated</p>
</blockquote>



<a name="192734320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192734320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192734320">(Apr 02 2020 at 22:17)</a>:</h4>
<p>you're speaking my language</p>



<a name="192734348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192734348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192734348">(Apr 02 2020 at 22:17)</a>:</h4>
<p>disclaimer, in <code>eyre</code> which is a fork of <code>anyhow</code> I renamed the <code>context</code> fn to <code>wrap_err</code></p>



<a name="192734463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192734463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192734463">(Apr 02 2020 at 22:18)</a>:</h4>
<p>can I ask what kind of context you're trying to provide? if its just runtime info I would argue that the right solution is tracing_error::SpanTrace</p>



<a name="192734517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192734517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192734517">(Apr 02 2020 at 22:19)</a>:</h4>
<p>or something similar</p>



<a name="192734549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192734549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192734549">(Apr 02 2020 at 22:19)</a>:</h4>
<p>but the idea is you wrap a scope with a span that has <code>thing</code> and <code>detail</code> as fields</p>



<a name="192734631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192734631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192734631">(Apr 02 2020 at 22:20)</a>:</h4>
<p>and then any errors that are created in that scope that also capture a SpanTrace will get those fields in the spantrace at the end</p>



<a name="192734663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192734663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192734663">(Apr 02 2020 at 22:20)</a>:</h4>
<div class="codehilite"><pre><span></span>   0: custom_error::do_another_thing
        with answer=42 will_succeed=false
          at examples/examples/custom_error.rs:42
   1: custom_error::do_something
        with foo=&quot;hello world&quot;
          at examples/examples/custom_error.rs:37
</pre></div>



<a name="192734752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192734752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192734752">(Apr 02 2020 at 22:21)</a>:</h4>
<p>because it sounds like you're inserting members that you want to include with an error that don't themselves represent a new error and you're doing it by creating a new error to wrap the existing one with the <code>context</code> fn</p>



<a name="192734801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192734801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192734801">(Apr 02 2020 at 22:21)</a>:</h4>
<p>lmk if this is accurate or not <span class="user-mention" data-user-id="239881">@Josh Triplett</span></p>



<a name="192735271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192735271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192735271">(Apr 02 2020 at 22:25)</a>:</h4>
<p>(One moment, interruption, will answer later with examples. Something came up.)</p>



<a name="192736980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192736980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192736980">(Apr 02 2020 at 22:43)</a>:</h4>
<p><span class="user-mention" data-user-id="220273">@Jane Lusby</span> Not sure what you mean by "runtime info".</p>



<a name="192737029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737029">(Apr 02 2020 at 22:44)</a>:</h4>
<p>like, local members that you want to see the values of at the time the error was created</p>



<a name="192737036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737036">(Apr 02 2020 at 22:44)</a>:</h4>
<p>but not necessarily stuff that is part of the error message</p>



<a name="192737049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737049">(Apr 02 2020 at 22:44)</a>:</h4>
<p>So, a couple of things...</p>



<a name="192737059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737059">(Apr 02 2020 at 22:44)</a>:</h4>
<p>First, this isn't meant as pure "debugging information"; this is information that may be useful to the end-user, not just me as the developer.</p>



<a name="192737077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737077">(Apr 02 2020 at 22:44)</a>:</h4>
<p>I want this error to be vaguely useful to my users.</p>



<a name="192737198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737198">(Apr 02 2020 at 22:46)</a>:</h4>
<p>As an example, I might have an error like "this git blob {hash} doesn't exist in the repository", and the context is <code>        let context = || format!("Processing tree {}", tree.id());</code></p>



<a name="192737251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737251">(Apr 02 2020 at 22:46)</a>:</h4>
<p>Because it's not very useful to say "hash {} didn't exist" without saying that it was the name N in the tree T (and "name N" would be nice to include too here).</p>



<a name="192737294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737294">(Apr 02 2020 at 22:47)</a>:</h4>
<p>okay</p>



<a name="192737322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737322">(Apr 02 2020 at 22:47)</a>:</h4>
<p>Just wanted to note that I have this frustration <em>every single time</em> I try to have nice errors in Rust. I've not found good solutions yet.</p>
<p>I usually have found that what I sort of want is to be able to say "here's some context" and then everything that happens after that (before that context goes out of scope, maybe?) would include it, sort of like how I think tracing's scopes work</p>



<a name="192737379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737379">(Apr 02 2020 at 22:48)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> Yes please!</p>



<a name="192737389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737389">(Apr 02 2020 at 22:48)</a>:</h4>
<p>so the <code>this git blob {hash} doesnt exist in the repository</code> is the error message</p>



<a name="192737402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737402">(Apr 02 2020 at 22:48)</a>:</h4>
<p>and <code>Processing tree {}</code> is context</p>



<a name="192737436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737436">(Apr 02 2020 at 22:48)</a>:</h4>
<p>so, maybe a better example, is that I usually actually want sort of "{hash} doesn't exist" -&gt; "in tree {}" -&gt; "in repository {}" etc</p>



<a name="192737449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737449">(Apr 02 2020 at 22:49)</a>:</h4>
<p>and usually these are in different functions sort of spread apart quite widely, in my experience</p>



<a name="192737474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737474">(Apr 02 2020 at 22:49)</a>:</h4>
<p>yea I'm still leaning towards tracing being a good fit but the debug_context! stuff would also work</p>



<a name="192737480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737480">(Apr 02 2020 at 22:49)</a>:</h4>
<p>though I dont thikn it would work well with <code>anyhow</code></p>



<a name="192737481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737481">(Apr 02 2020 at 22:49)</a>:</h4>
<p><span class="user-mention" data-user-id="220273">@Jane Lusby</span> Right. I'm currently using <code>anyhow</code>, and <code>.with_context(context)?</code>.</p>



<a name="192737487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737487">(Apr 02 2020 at 22:49)</a>:</h4>
<p>because anyhow doesnt allow for adding context that isnt itself an error in your chain of errors</p>



<a name="192737500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737500">(Apr 02 2020 at 22:49)</a>:</h4>
<p>which you could just do, but I think its bad personally</p>



<a name="192737554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737554">(Apr 02 2020 at 22:50)</a>:</h4>
<p>this is the single reason why I forked anyhow</p>



<a name="192737568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737568">(Apr 02 2020 at 22:50)</a>:</h4>
<p>hm, well, actually, I don't usually care  - in almost all cases where I do this it's just going to get printed at the end, I don't have any downcasting etc</p>



<a name="192737603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737603">(Apr 02 2020 at 22:50)</a>:</h4>
<p><a href="https://docs.rs/eyre/0.3.5/src/eyre/lib.rs.html#466-471" title="https://docs.rs/eyre/0.3.5/src/eyre/lib.rs.html#466-471">https://docs.rs/eyre/0.3.5/src/eyre/lib.rs.html#466-471</a></p>



<a name="192737607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737607">(Apr 02 2020 at 22:50)</a>:</h4>
<p>(indeed whenever I start wanting to downcast I usually try to drop the opaque <code>Error</code> structs and go for some enum or something</p>



<a name="192737634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737634">(Apr 02 2020 at 22:51)</a>:</h4>
<p>note, eyre adds a context type parameter</p>



<a name="192737649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737649">(Apr 02 2020 at 22:51)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> Likewise. If I'm using <code>anyhow</code> it's because the only thing that'll ever happen with an error is reporting it and exiting gracefully.</p>



<a name="192737705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737705">(Apr 02 2020 at 22:51)</a>:</h4>
<p>so you could in theory have debug_context expose he fields in a threadlocal, and then have <code>wrap_err</code> grab that context and add it to the set of contexts in the ErrReport</p>



<a name="192737775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737775">(Apr 02 2020 at 22:52)</a>:</h4>
<p><span class="user-mention" data-user-id="220273">@Jane Lusby</span> That doesn't sound especially zero-overhead.</p>



<a name="192737797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737797">(Apr 02 2020 at 22:52)</a>:</h4>
<p>(Small note: I think in general given that there's a lot of "mode du jour" and shifting sands wrt. error handling utility libraries, that makes me pretty skeptical of anything approaching language level changes.)</p>



<a name="192737821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737821">(Apr 02 2020 at 22:52)</a>:</h4>
<p>(Like... <code>anyhow</code> is a <em>very</em> new library)</p>



<a name="192737846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737846">(Apr 02 2020 at 22:52)</a>:</h4>
<p>^</p>



<a name="192737847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737847">(Apr 02 2020 at 22:52)</a>:</h4>
<p>big agree on that</p>



<a name="192737852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737852">(Apr 02 2020 at 22:53)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> We're not at that phase now, we're at the brainstorming phase of "what does the thing we want look like".</p>



<a name="192737879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737879">(Apr 02 2020 at 22:53)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> yeah hence parenthetical <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="192737884"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737884" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737884">(Apr 02 2020 at 22:53)</a>:</h4>
<p>okay so you want a context</p>



<a name="192737885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737885">(Apr 02 2020 at 22:53)</a>:</h4>
<p>thats available locally</p>



<a name="192737895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737895">(Apr 02 2020 at 22:53)</a>:</h4>
<p><span class="user-mention" data-user-id="220273">@Jane Lusby</span> So, I'm not excited about the idea of switching error-handling libraries. I'm honestly hopeful that the <em>next</em> time that I switch will be when I switch to <code>std</code>.</p>



<a name="192737908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737908">(Apr 02 2020 at 22:53)</a>:</h4>
<p>okay</p>



<a name="192737911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737911">(Apr 02 2020 at 22:53)</a>:</h4>
<p>I think the hard part for me is figuring out how to actually associate the context</p>



<a name="192737973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737973">(Apr 02 2020 at 22:54)</a>:</h4>
<p>so that leaves you with inserting the context into the error chain</p>



<a name="192737990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192737990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192737990">(Apr 02 2020 at 22:54)</a>:</h4>
<p>I'm not saying that I'm completely unwilling to switch at this point, but it would need to be for a reason stronger than "it doesn't feel right for it to be part of the chain of errors". :)</p>



<a name="192738007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738007">(Apr 02 2020 at 22:54)</a>:</h4>
<p>thats fair</p>



<a name="192738017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738017">(Apr 02 2020 at 22:54)</a>:</h4>
<p>I also hope that <code>anyhow</code> might be amenable to introducing a way to do this.</p>



<a name="192738030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738030">(Apr 02 2020 at 22:54)</a>:</h4>
<p>anyway, need to run, but will catch up later</p>



<a name="192738041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738041">(Apr 02 2020 at 22:54)</a>:</h4>
<p>maybe write up something more long form...</p>



<a name="192738136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738136">(Apr 02 2020 at 22:55)</a>:</h4>
<p>okay well, lets still see if we cant figure out what we would need to have added to anyhow</p>



<a name="192738174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738174">(Apr 02 2020 at 22:56)</a>:</h4>
<p>so you want to specify the context once</p>



<a name="192738199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738199">(Apr 02 2020 at 22:56)</a>:</h4>
<p>Well, once per new information to the context.</p>



<a name="192738203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738203">(Apr 02 2020 at 22:56)</a>:</h4>
<p>and then have any call within that scope use that context implicitly</p>



<a name="192738244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738244">(Apr 02 2020 at 22:56)</a>:</h4>
<p>Right. Minimum would be "open a scope within which every error gets this context". Bonus if I can also augment the current context without opening a new nested block.</p>



<a name="192738252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738252">(Apr 02 2020 at 22:56)</a>:</h4>
<p>(The difference mostly being indentation, frankly.)</p>



<a name="192738267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738267">(Apr 02 2020 at 22:57)</a>:</h4>
<p>mhmm</p>



<a name="192738276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738276">(Apr 02 2020 at 22:57)</a>:</h4>
<p>and tracing is off the table?</p>



<a name="192738288"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738288" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738288">(Apr 02 2020 at 22:57)</a>:</h4>
<p>I know very little about tracing.</p>



<a name="192738291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738291">(Apr 02 2020 at 22:57)</a>:</h4>
<p>because this is exactly what tracing-error + tracing is designed to do</p>



<a name="192738301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738301">(Apr 02 2020 at 22:57)</a>:</h4>
<p>so with your specific example</p>



<a name="192738304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738304">(Apr 02 2020 at 22:57)</a>:</h4>
<p>it would look like this vaguely</p>



<a name="192738407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738407">(Apr 02 2020 at 22:58)</a>:</h4>
<p>One piece of information: I'm writing performance-sensitive code, where my inner loops run enough times that a tiny change to them can cost a substantial fraction of my runtime, so it's important that error handling add zero overhead if not erroring.</p>



<a name="192738421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738421">(Apr 02 2020 at 22:58)</a>:</h4>
<p>I don't know enough about tracing or how it works to know if it has that property.</p>



<a name="192738438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738438">(Apr 02 2020 at 22:59)</a>:</h4>
<p>tracing is pretty low overhead but it writes eagerly, tho it does so without allocating most of the time</p>



<a name="192738462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738462">(Apr 02 2020 at 22:59)</a>:</h4>
<p>so each time you encounter a span it has to copy the display data into the registry</p>



<a name="192738487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738487">(Apr 02 2020 at 22:59)</a>:</h4>
<p>Then that's very likely to be too much overhead, unfortunately.</p>



<a name="192738494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738494">(Apr 02 2020 at 22:59)</a>:</h4>
<p>okay so no tracing</p>



<a name="192738513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738513">(Apr 02 2020 at 23:00)</a>:</h4>
<p>At least not unless there's a variant of tracing that doesn't have that property, yeah. Sorry; from the descriptions of it it does sound quite nice.</p>



<a name="192738591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738591">(Apr 02 2020 at 23:00)</a>:</h4>
<p>not that I know of but eliza is more of an expert</p>



<a name="192738618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738618">(Apr 02 2020 at 23:00)</a>:</h4>
<p><span class="user-mention" data-user-id="198819">@David Barsky</span> has more experience using tracing in perf critical code than me</p>



<a name="192738628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738628">(Apr 02 2020 at 23:00)</a>:</h4>
<p>he can probably also chime in</p>



<a name="192738664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738664">(Apr 02 2020 at 23:01)</a>:</h4>
<p>so I dont know how you would pass it implicitly</p>



<a name="192738680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738680">(Apr 02 2020 at 23:01)</a>:</h4>
<p>without using thread locals</p>



<a name="192738681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738681">(Apr 02 2020 at 23:01)</a>:</h4>
<p>As a random example, I was curious how much difference <code>.with_context(|| format!(...))</code> versus <code>.context(format!(...))</code> made, and the answer turned out to be "3-4% of my total runtime".</p>



<a name="192738701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738701">(Apr 02 2020 at 23:01)</a>:</h4>
<p>nicee</p>



<a name="192738726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738726">(Apr 02 2020 at 23:01)</a>:</h4>
<p>but tracing will probably be a lot less than that</p>



<a name="192738734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738734">(Apr 02 2020 at 23:01)</a>:</h4>
<p>because format involves allocations that tracing wont</p>



<a name="192738741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738741">(Apr 02 2020 at 23:01)</a>:</h4>
<p>it might be easy enough to benchmark</p>



<a name="192738743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738743">(Apr 02 2020 at 23:01)</a>:</h4>
<p>Fair.</p>



<a name="192738800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738800">(Apr 02 2020 at 23:02)</a>:</h4>
<p>Quite possibly worth the experiment.</p>



<a name="192738808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738808">(Apr 02 2020 at 23:02)</a>:</h4>
<p>you can just setup a subscriber, throw  aspan there, capture a spantrace and immediately discard it and see what the perf impact is</p>



<a name="192738848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738848">(Apr 02 2020 at 23:02)</a>:</h4>
<p>well you probably wouldnt want to capture the spantrace</p>



<a name="192738881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738881">(Apr 02 2020 at 23:03)</a>:</h4>
<p>or only capture it and discard it inside of one of the closures that only happen on the error path</p>



<a name="192738883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738883">(Apr 02 2020 at 23:03)</a>:</h4>
<p>anyways</p>



<a name="192738917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738917">(Apr 02 2020 at 23:03)</a>:</h4>
<p>i feel like you can get pretty close to what you want with <code>format_args!</code> and <code>context</code> maybe</p>



<a name="192738918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738918">(Apr 02 2020 at 23:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="220273">Jane Lusby</span> <a href="#narrow/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts/near/192738664" title="#narrow/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts/near/192738664">said</a>:</p>
<blockquote>
<p>so I dont know how you would pass it implicitly</p>
</blockquote>
<p><span class="user-mention silent" data-user-id="220273">Jane Lusby</span> <a href="#narrow/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts/near/192738680" title="#narrow/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts/near/192738680">said</a>:</p>
<blockquote>
<p>without using thread locals</p>
</blockquote>
<p>Assume for the moment that we had <code>try</code> blocks. Then I would hope for something that's effectively <code>try { ... }.with_context(|| ...)?</code> wrapped in a macro.</p>



<a name="192738940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738940">(Apr 02 2020 at 23:03)</a>:</h4>
<p>aah yea that would work</p>



<a name="192738986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192738986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192738986">(Apr 02 2020 at 23:04)</a>:</h4>
<p>With the context first rather than last.</p>



<a name="192739010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739010">(Apr 02 2020 at 23:04)</a>:</h4>
<p>format_args is evaluated lazily right?</p>



<a name="192739025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739025">(Apr 02 2020 at 23:04)</a>:</h4>
<p>does it impl display</p>



<a name="192739037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739037">(Apr 02 2020 at 23:04)</a>:</h4>
<p>I don't know the internals of the format machinery.</p>



<a name="192739067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739067">(Apr 02 2020 at 23:05)</a>:</h4>
<p>it does impl display</p>



<a name="192739100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739100">(Apr 02 2020 at 23:05)</a>:</h4>
<p>oh but you cant use it as context</p>



<a name="192739108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739108">(Apr 02 2020 at 23:05)</a>:</h4>
<p>because its not 'static</p>



<a name="192739116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739116">(Apr 02 2020 at 23:05)</a>:</h4>
<p>And <code>context</code> versus <code>with_context</code> isn't the primary source of my verbosity. It's changing the one character <code>?</code> into <code>.with_context(context)?</code>.</p>



<a name="192739138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739138">(Apr 02 2020 at 23:05)</a>:</h4>
<p>The only other language-level thing that would help would be the ability to say "the rest of this block is wrapped in this macro", which would help with formatting and indentation, but is by no means required.</p>



<a name="192739205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739205">(Apr 02 2020 at 23:06)</a>:</h4>
<p>(And could technically be done by a proc macro attached to the function, though, ow.)</p>



<a name="192739215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739215">(Apr 02 2020 at 23:06)</a>:</h4>
<p>yea, i think you should experiment with tracing personally</p>



<a name="192739223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739223">(Apr 02 2020 at 23:06)</a>:</h4>
<p>because if that works its everything you want</p>



<a name="192739233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739233">(Apr 02 2020 at 23:06)</a>:</h4>
<p>you just enter the span and it uses RAII to drop the context when it goes out of scope</p>



<a name="192739243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739243">(Apr 02 2020 at 23:06)</a>:</h4>
<p>I'll keep that in mind; it does sound nice.</p>



<a name="192739244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739244">(Apr 02 2020 at 23:06)</a>:</h4>
<p>and then you just have to get anyhow (or eyre which already can do this) to capture the SpanTrace when its constructed</p>



<a name="192739293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739293">(Apr 02 2020 at 23:07)</a>:</h4>
<p>beyond that I don't have any ready solutions for you other than a macro that creates a nice context object given some fields which can then be passed into <code>.with_context()</code></p>



<a name="192739313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739313">(Apr 02 2020 at 23:07)</a>:</h4>
<p>I appreciate you taking the time to ponder this problem.</p>



<a name="192739359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739359">(Apr 02 2020 at 23:08)</a>:</h4>
<p>my pleasure</p>



<a name="192739373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739373">(Apr 02 2020 at 23:08)</a>:</h4>
<p>And I do hope that we get something satisfying into the standard library. I appreciate you helping to drive error-handling forward.</p>



<a name="192739377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739377">(Apr 02 2020 at 23:08)</a>:</h4>
<p>any excuse to get familiar with more error handling use cases</p>



<a name="192739386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739386">(Apr 02 2020 at 23:08)</a>:</h4>
<p>ty ^_^</p>



<a name="192739406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739406">(Apr 02 2020 at 23:08)</a>:</h4>
<p>yea i think the error reporting part (something like <code>anyhow</code>) will probably be the last thing to get into std</p>



<a name="192739416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739416">(Apr 02 2020 at 23:08)</a>:</h4>
<p>also im surprised you're using anyhow at all in a perf critical piece of code</p>



<a name="192739438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739438">(Apr 02 2020 at 23:09)</a>:</h4>
<p>but i might have bad intuition about the cost of allocations</p>



<a name="192739450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739450">(Apr 02 2020 at 23:09)</a>:</h4>
<p><span class="user-mention" data-user-id="220273">@Jane Lusby</span> The non-error path is performance critical, but it doesn't allocate.</p>



<a name="192739456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739456">(Apr 02 2020 at 23:09)</a>:</h4>
<p>aaaaah</p>



<a name="192739462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739462">(Apr 02 2020 at 23:09)</a>:</h4>
<p>that makes sense</p>



<a name="192739463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739463">(Apr 02 2020 at 23:09)</a>:</h4>
<p>The error path is emphatically <em>not</em> performance-critical.</p>



<a name="192739483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739483">(Apr 02 2020 at 23:09)</a>:</h4>
<p>i should internalize that better</p>



<a name="192739487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739487">(Apr 02 2020 at 23:09)</a>:</h4>
<p>that should be obvious</p>



<a name="192739538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739538">(Apr 02 2020 at 23:10)</a>:</h4>
<p>Yeah, it took me a <em>long</em> time.</p>



<a name="192739553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739553">(Apr 02 2020 at 23:10)</a>:</h4>
<p>I was allergic to anything even close to <code>Box&lt;dyn Error&gt;</code> for the longest time.</p>



<a name="192739577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739577">(Apr 02 2020 at 23:10)</a>:</h4>
<p>Then I finally started realizing how much overhead an enum error type had.</p>



<a name="192739585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739585">(Apr 02 2020 at 23:11)</a>:</h4>
<p>is it more?</p>



<a name="192739598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739598">(Apr 02 2020 at 23:11)</a>:</h4>
<p>In size, very much so.</p>



<a name="192739601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739601">(Apr 02 2020 at 23:11)</a>:</h4>
<p>or just not much less</p>



<a name="192739604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739604">(Apr 02 2020 at 23:11)</a>:</h4>
<p>ah yes</p>



<a name="192739609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739609">(Apr 02 2020 at 23:11)</a>:</h4>
<p>especially if they get deep</p>



<a name="192739645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739645">(Apr 02 2020 at 23:11)</a>:</h4>
<p>and that would impact the hot path too</p>



<a name="192739647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739647">(Apr 02 2020 at 23:11)</a>:</h4>
<p>Deep or embedding lots of useful error context that itself includes allocations anyway (like a string).</p>



<a name="192739688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739688">(Apr 02 2020 at 23:12)</a>:</h4>
<p>And exactly.</p>



<a name="192739695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739695">(Apr 02 2020 at 23:12)</a>:</h4>
<p>where as anyhow is 1 ptr wide on the stack</p>



<a name="192739704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739704">(Apr 02 2020 at 23:12)</a>:</h4>
<p>makes sense</p>



<a name="192739712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739712">(Apr 02 2020 at 23:12)</a>:</h4>
<p><em>That</em> was the realization that got me to like <code>anyhow</code> very much: that I don't care about the performance of the error path, I care about the performance of the non-error path, and I was hurting it by using custom error types.</p>



<a name="192739763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739763">(Apr 02 2020 at 23:13)</a>:</h4>
<p>And in particular that <code>Result&lt;T, MyCarefullyConstructedError&gt;</code> was going to be much much bigger than T for almost any T I had.</p>



<a name="192739793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739793">(Apr 02 2020 at 23:13)</a>:</h4>
<p>yea</p>



<a name="192739809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739809">(Apr 02 2020 at 23:13)</a>:</h4>
<p>anyways</p>



<a name="192739859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739859">(Apr 02 2020 at 23:14)</a>:</h4>
<p>try out tracing error, <a href="https://github.com/tokio-rs/tracing/blob/master/examples/examples/custom_error.rs" title="https://github.com/tokio-rs/tracing/blob/master/examples/examples/custom_error.rs">https://github.com/tokio-rs/tracing/blob/master/examples/examples/custom_error.rs</a> this should be a good example to use to get the necessary pieces</p>



<a name="192739869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739869">(Apr 02 2020 at 23:14)</a>:</h4>
<p>(The other allergy I had to <code>dyn Error</code> and <code>anyhow</code> was this ingrained systems-programming concept of "you can't allocate on the error path! What happens if something goes wrong with allocation!".)</p>



<a name="192739872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739872">(Apr 02 2020 at 23:14)</a>:</h4>
<p>though that uses <code>#[instrument]</code> instead of ever invoking the span macros directly</p>



<a name="192739906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739906">(Apr 02 2020 at 23:14)</a>:</h4>
<p>ha yea, one of my friends has to do zero allocation in the error path for that exact reason</p>



<a name="192739912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739912">(Apr 02 2020 at 23:14)</a>:</h4>
<p>tho hes doing os work</p>



<a name="192739915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739915">(Apr 02 2020 at 23:15)</a>:</h4>
<p>(To which I have to keep reminding myself that I'm not writing an operating system or a memory allocator (at the moment), and if allocation fails I have much worse problems.)</p>



<a name="192739952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192739952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192739952">(Apr 02 2020 at 23:15)</a>:</h4>
<p>lol</p>



<a name="192740124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192740124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192740124">(Apr 02 2020 at 23:17)</a>:</h4>
<p>ill think more about the context stuff incase tracing doesnt work out and ill let you know if I think of anything</p>



<a name="192740204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192740204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192740204">(Apr 02 2020 at 23:18)</a>:</h4>
<p>if we just had postfix macros...</p>



<a name="192740669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192740669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192740669">(Apr 02 2020 at 23:25)</a>:</h4>
<p>How might postfix macros help here? Note that I want to write <code>?</code>, not <code>.c!()?</code> or similar.</p>



<a name="192740697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192740697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192740697">(Apr 02 2020 at 23:25)</a>:</h4>
<p>(I want postfix macros too, but I'm wondering how you see them being used in this context.)</p>



<a name="192740713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192740713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192740713">(Apr 02 2020 at 23:25)</a>:</h4>
<p>oh i was thinking if you could define a postfix macro that replaced <code>context</code> and called it internally and also inserted your context that it would accomplish your needs</p>



<a name="192740816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192740816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192740816">(Apr 02 2020 at 23:26)</a>:</h4>
<p>so there would be one macro call that basically defines the scope and maybe also defines the context macro and creates the closure to format in the members</p>



<a name="192740854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192740854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192740854">(Apr 02 2020 at 23:27)</a>:</h4>
<p>Honestly, it isn't just verbosity that prompted me to want this. It's "oops, I almost forgot what was in my <code>let context = || ...;</code> and used the wrong context for that error, this needs to be more automatic and scoped".</p>



<a name="192740981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192740981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192740981">(Apr 02 2020 at 23:28)</a>:</h4>
<p>hmmm</p>



<a name="192741006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741006">(Apr 02 2020 at 23:29)</a>:</h4>
<p>so the thing you're afraid of is this</p>



<a name="192741044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741044">(Apr 02 2020 at 23:29)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">blah</span><span class="p">(</span><span class="n">local</span>: <span class="kt">i32</span><span class="p">,</span><span class="w"> </span><span class="n">local2</span>: <span class="kt">i32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;</span><span class="p">(),</span><span class="w"> </span><span class="n">Error</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">error_context</span><span class="o">!</span><span class="p">(</span><span class="n">local</span><span class="p">);</span><span class="w"></span>

<span class="w">    </span><span class="n">fallible_fn</span><span class="p">().</span><span class="n">context</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;the error message&quot;</span><span class="p">)</span><span class="o">?</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="c1">// error_context!(local2); OOPS forgot to add</span>

<span class="w">    </span><span class="n">fallible_fn2</span><span class="p">().</span><span class="n">context</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;the error message2&quot;</span><span class="p">)</span><span class="o">?</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="192741057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741057">(Apr 02 2020 at 23:29)</a>:</h4>
<p>In terms of <code>error_context!</code> yes.</p>



<a name="192741147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741147">(Apr 02 2020 at 23:30)</a>:</h4>
<p>but you dont want to add blocks with indentation</p>



<a name="192741161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741161">(Apr 02 2020 at 23:30)</a>:</h4>
<p>or is it specifically closures that you dont want</p>



<a name="192741179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741179">(Apr 02 2020 at 23:31)</a>:</h4>
<p>I don't mind adding blocks with indentation, though I'd love to not have to.</p>



<a name="192741185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741185">(Apr 02 2020 at 23:31)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">blah</span><span class="p">(</span><span class="n">local</span>: <span class="kt">i32</span><span class="p">,</span><span class="w"> </span><span class="n">local2</span>: <span class="kt">i32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;</span><span class="p">(),</span><span class="w"> </span><span class="n">Error</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">error_context</span><span class="o">!</span><span class="p">(</span><span class="n">local</span><span class="p">);</span><span class="w"></span>

<span class="w">        </span><span class="n">fallible_fn</span><span class="p">().</span><span class="n">context</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;the error message&quot;</span><span class="p">)</span><span class="o">?</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="c1">// error_context!(local2); OOPS forgot to add</span>

<span class="w">    </span><span class="n">fallible_fn2</span><span class="p">().</span><span class="n">context</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;the error message2&quot;</span><span class="p">)</span><span class="o">?</span><span class="p">;</span><span class="w"> </span><span class="c1">// OOPS compiler error, context! not defined, yay!</span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="192741195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741195">(Apr 02 2020 at 23:31)</a>:</h4>
<p>What almost happened was this:</p>



<a name="192741334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741334">(Apr 02 2020 at 23:33)</a>:</h4>
<p>In this case, it was:</p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">walk_tree</span><span class="p">(</span><span class="n">tree</span>: <span class="nc">Tree</span><span class="p">,</span><span class="w"> </span><span class="p">...)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">context</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="n">format</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;Processing tree {}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">tree</span><span class="p">.</span><span class="n">id</span><span class="p">());</span><span class="w"></span>
<span class="w">    </span><span class="p">...</span><span class="w"></span>
<span class="w">    </span><span class="k">for</span><span class="w"> </span><span class="n">entry</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">tree</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="p">...</span><span class="w"></span>
<span class="w">        </span><span class="k">match</span><span class="w"> </span><span class="n">mode</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="p">...</span><span class="w"></span>
<span class="w">            </span><span class="n">FileMode</span>::<span class="n">Tree</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="p">...</span><span class="w"></span>
<span class="w">                </span><span class="n">some_call</span><span class="p">().</span><span class="n">with_context</span><span class="p">(</span><span class="n">context</span><span class="p">)</span><span class="o">?</span><span class="p">;</span><span class="w"> </span><span class="c1">// OOPS this context is the tree I&#39;m walking not the subtree I&#39;m about to recurse into</span>
</pre></div>



<a name="192741385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741385">(Apr 02 2020 at 23:33)</a>:</h4>
<p>because you had some other error in the top level that could throw before the entry iteration</p>



<a name="192741394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741394">(Apr 02 2020 at 23:34)</a>:</h4>
<p>Right.</p>



<a name="192741446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741446">(Apr 02 2020 at 23:34)</a>:</h4>
<p>This is a long function that has calls with <code>?</code> on every other line.</p>



<a name="192741465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741465">(Apr 02 2020 at 23:34)</a>:</h4>
<p>Most of which will produce inscrutable errors without some idea of "this happened while I was processing a tree".</p>



<a name="192741474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741474">(Apr 02 2020 at 23:34)</a>:</h4>
<p>yea, even with tracing error if you forget to add the span for the entry then you'll only get the context for the tree, the difference is it grabs all active spans when it gets the span trace</p>



<a name="192741497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741497">(Apr 02 2020 at 23:35)</a>:</h4>
<p>so if you have the context at the top level and the context for the entry you'll get them each as different frames essentially</p>



<a name="192741502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741502">(Apr 02 2020 at 23:35)</a>:</h4>
<p>to borrow backtrace parlance</p>



<a name="192741603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741603">(Apr 02 2020 at 23:36)</a>:</h4>
<p>and unless the top level context is never used after the for loop you're gonna have trouble scoping that</p>



<a name="192741613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741613">(Apr 02 2020 at 23:36)</a>:</h4>
<p>or in any situation where the scope for one context completely contains the scope of another</p>



<a name="192741630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741630">(Apr 02 2020 at 23:37)</a>:</h4>
<p>im not sure if that problem is solvable</p>



<a name="192741632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192741632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192741632">(Apr 02 2020 at 23:37)</a>:</h4>
<p>:/</p>



<a name="192742141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192742141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192742141">(Apr 02 2020 at 23:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts/near/192739763" title="#narrow/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts/near/192739763">said</a>:</p>
<blockquote>
<p>And in particular that <code>Result&lt;T, MyCarefullyConstructedError&gt;</code> was going to be much much bigger than T for almost any T I had.</p>
</blockquote>
<p>Oh yeah; in the compiler we basically do <code>pub struct DiagnosticBuilder&lt;'a&gt;(Box&lt;DiagnosticBuilderInner&lt;'a&gt;&gt;);</code> and <code>type PResult&lt;'a, T&gt; = Result&lt;T, DiagnosticBuilder&lt;'a&gt;&gt;;</code> where <code>PResult&lt;'a, T&gt;</code> is the error type used all over the place.</p>



<a name="192742151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192742151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192742151">(Apr 02 2020 at 23:43)</a>:</h4>
<p>boxing that up had some nice perf wins</p>



<a name="192742224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192742224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192742224">(Apr 02 2020 at 23:44)</a>:</h4>
<p>(<code>DiagnosticBuilderInner</code> is a pretty large type, <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/diagnostic_builder/struct.DiagnosticBuilderInner.html" title="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/diagnostic_builder/struct.DiagnosticBuilderInner.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/diagnostic_builder/struct.DiagnosticBuilderInner.html</a>)</p>



<a name="192742278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192742278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192742278">(Apr 02 2020 at 23:45)</a>:</h4>
<blockquote>
<p>In theory, return value optimization (RVO) should avoid unnecessary copying. In practice, it does not (at the time of writing).</p>
</blockquote>



<a name="192742283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192742283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192742283">(Apr 02 2020 at 23:45)</a>:</h4>
<p>is this still the case? :(</p>



<a name="192742571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192742571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192742571">(Apr 02 2020 at 23:49)</a>:</h4>
<p>~</p>



<a name="192745222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192745222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Barsky <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192745222">(Apr 03 2020 at 00:24)</a>:</h4>
<p>Hi! Few notes on tracing:</p>
<ul>
<li>tracing should be pretty cheap/no cost at all, depending on how you set it up. Cheaper and more performant than log, I’d guess </li>
<li>tracing supports, at the lowest bounds, no_std + alloc.</li>
<li>in the next few days, we’ll start pooling all our allocations in <code>tracing</code>, which should be a nice win.</li>
</ul>



<a name="192745716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192745716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192745716">(Apr 03 2020 at 00:31)</a>:</h4>
<p><span class="user-mention" data-user-id="220273">@Jane Lusby</span> Did you send a message that @-ed me, and then edit it? I had a notification and now can't find the corresponding message.</p>



<a name="192745822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192745822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192745822">(Apr 03 2020 at 00:33)</a>:</h4>
<p>yea,</p>



<a name="192745836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192745836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192745836">(Apr 03 2020 at 00:33)</a>:</h4>
<p>eliza was asking if you're using log currently but I didnt think it was relevant after interrogating her about why she wanted to know</p>



<a name="192745861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192745861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192745861">(Apr 03 2020 at 00:33)</a>:</h4>
<p>so i did my best to delete it :&lt;</p>



<a name="192745868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192745868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192745868">(Apr 03 2020 at 00:33)</a>:</h4>
<p>thats the <code>~</code> msg</p>



<a name="192852500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192852500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192852500">(Apr 03 2020 at 19:23)</a>:</h4>
<p>Ah, makes sense.</p>



<a name="192852544"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/192852544" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#192852544">(Apr 03 2020 at 19:23)</a>:</h4>
<p>Thanks.</p>



<a name="194209513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/194209513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#194209513">(Apr 15 2020 at 18:41)</a>:</h4>
<p>I didn't read this topic</p>



<a name="194209519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/194209519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#194209519">(Apr 15 2020 at 18:42)</a>:</h4>
<p>Did I miss anything? :)</p>



<a name="194209630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/194209630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#194209630">(Apr 15 2020 at 18:42)</a>:</h4>
<p>You might be interested to read it. It was partly inspired by your comments about trying out fehler and thinking about error-handling patterns.</p>



<a name="194209896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/194209896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#194209896">(Apr 15 2020 at 18:44)</a>:</h4>
<p>tl;dr: in the course of writing code with error-handling, I ran into a case that feels like it could use some language-level help, namely providing context for errors to clarify an error that would otherwise get propagated with <code>?</code> without enough explanation to make sense of it.</p>



<a name="194210022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/194210022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#194210022">(Apr 15 2020 at 18:45)</a>:</h4>
<p>Ah. On a related note I would very much like some procedural macros to automatically give context from functions. <span class="user-mention" data-user-id="211722">@Yoshua Wuyts</span> had some interesting libraries here.</p>



<a name="194210302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/194210302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#194210302">(Apr 15 2020 at 18:47)</a>:</h4>
<p>I do think that's a good idea. But that's also often not sufficient for human-readable errors.</p>



<a name="194210411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/194210411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#194210411">(Apr 15 2020 at 18:48)</a>:</h4>
<p>For instance, I might need to do a bit of computation to give a more helpful  error message, and I can't do that computation until a little bit into the function, so failures <em>after</em> that point should include that information.</p>



<a name="194224068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/194224068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#194224068">(Apr 15 2020 at 20:37)</a>:</h4>
<p>I think this also has interesting parallels to my desire for some sort of context aware Debug and such, too, along with potentially moving things like async executors out of TLS ergonomically. Generally "context" that you want to thread through your program without passing explicitly, and likely through things like iterator adapters where it's not even possible much of the time</p>



<a name="194224393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/194224393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#194224393">(Apr 15 2020 at 20:40)</a>:</h4>
<p>Yeah. I feel like I do actually want something like <code>try { ... }.with_context(|| compute and provide more context)?</code> , added "on the way out" of a scope. The one addition is that I'd like to be able to "wrap the rest of the function" in that, rather than it being a purely nesting block.</p>



<a name="194224485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/194224485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#194224485">(Apr 15 2020 at 20:41)</a>:</h4>
<p>The former is writable with no language additions other than <code>try</code>. The latter would need a language change, or a proc macro.</p>



<a name="194237243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/194237243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#194237243">(Apr 15 2020 at 22:38)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> Have you tried <code>snafu</code>? It has some proc macro magic to let you easily pass and format context into your errors. <a href="https://docs.rs/snafu" title="https://docs.rs/snafu">https://docs.rs/snafu</a></p>
<div class="codehilite"><pre><span></span><span class="cp">#[derive(Debug, Snafu)]</span><span class="w"></span>
<span class="k">enum</span> <span class="nc">Error</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="cp">#[snafu(display(</span><span class="s">&quot;Could not open config from {}: {}&quot;</span><span class="cp">, filename.display(), source))]</span><span class="w"></span>
<span class="w">    </span><span class="n">OpenConfig</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">filename</span>: <span class="nc">PathBuf</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="n">source</span>: <span class="nc">std</span>::<span class="n">io</span>::<span class="n">Error</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="p">},</span><span class="w"></span>
<span class="w">    </span><span class="cp">#[snafu(display(</span><span class="s">&quot;Could not save config to {}: {}&quot;</span><span class="cp">, filename.display(), source))]</span><span class="w"></span>
<span class="w">    </span><span class="n">SaveConfig</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">filename</span>: <span class="nc">PathBuf</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="n">source</span>: <span class="nc">std</span>::<span class="n">io</span>::<span class="n">Error</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="p">},</span><span class="w"></span>
<span class="w">    </span><span class="cp">#[snafu(display(</span><span class="s">&quot;The user id {} is invalid&quot;</span><span class="cp">, user_id))]</span><span class="w"></span>
<span class="w">    </span><span class="n">UserIdInvalid</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">user_id</span>: <span class="kt">i32</span><span class="p">,</span><span class="w"> </span><span class="n">backtrace</span>: <span class="nc">Backtrace</span><span class="w"> </span><span class="p">},</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">type</span> <span class="nb">Result</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Error</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span>::<span class="n">result</span>::<span class="nb">Result</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">log_in_user</span><span class="o">&lt;</span><span class="n">P</span><span class="o">&gt;</span><span class="p">(</span><span class="n">config_root</span>: <span class="nc">P</span><span class="p">,</span><span class="w"> </span><span class="n">user_id</span>: <span class="kt">i32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;</span><span class="kt">bool</span><span class="o">&gt;</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="n">P</span>: <span class="nb">AsRef</span><span class="o">&lt;</span><span class="n">Path</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">config_root</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">config_root</span><span class="p">.</span><span class="n">as_ref</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">filename</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">config_root</span><span class="p">.</span><span class="n">join</span><span class="p">(</span><span class="s">&quot;config.toml&quot;</span><span class="p">);</span><span class="w"></span>

<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">config</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">fs</span>::<span class="n">read</span><span class="p">(</span><span class="n">filename</span><span class="p">).</span><span class="n">context</span><span class="p">(</span><span class="n">OpenConfig</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">filename</span><span class="w"> </span><span class="p">})</span><span class="o">?</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="c1">// Perform updates to config</span>
<span class="w">    </span><span class="n">fs</span>::<span class="n">write</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span><span class="w"> </span><span class="n">config</span><span class="p">).</span><span class="n">context</span><span class="p">(</span><span class="n">SaveConfig</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">filename</span><span class="w"> </span><span class="p">})</span><span class="o">?</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="n">ensure</span><span class="o">!</span><span class="p">(</span><span class="n">user_id</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">42</span><span class="p">,</span><span class="w"> </span><span class="n">UserIdInvalid</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">user_id</span><span class="w"> </span><span class="p">});</span><span class="w"></span>

<span class="w">    </span><span class="nb">Ok</span><span class="p">(</span><span class="kc">true</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="194262197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/194262197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#194262197">(Apr 16 2020 at 06:37)</a>:</h4>
<p><span class="user-mention" data-user-id="219696">@XAMPPRocky</span> I'm not sure what I'm supposed to be seeing there. Most of that looks very similar to <code>thiserror</code>. And that doesn't seem to solve the context problem at all. It just provides context functions; they still need calling before every <code>?</code>.</p>



<a name="194278310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/194278310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#194278310">(Apr 16 2020 at 09:36)</a>:</h4>
<p>Ah, I only saw the context discussion. Not the “provide context without calling context”.</p>



<a name="222137532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222137532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hossein Mayboudi <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222137532">(Jan 08 2021 at 23:06)</a>:</h4>
<p><span class="user-mention silent" data-user-id="220273">Jane Lusby</span> <a href="#narrow/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts/near/192734463">said</a>:</p>
<blockquote>
<p>can I ask what kind of context you're trying to provide? if its just runtime info I would argue that the right solution is tracing_error::SpanTrace</p>
</blockquote>
<p>Hi do you have any experience with using thiserror and tracing_error? if not do you have any idea how can I use them together?</p>



<a name="222174296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222174296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222174296">(Jan 09 2021 at 14:59)</a>:</h4>
<p>Yes</p>



<a name="222174341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222174341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222174341">(Jan 09 2021 at 15:00)</a>:</h4>
<p>What problems are you running into <span class="user-mention" data-user-id="378207">@Hossein Mayboudi</span>?</p>



<a name="222222944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222222944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hossein Mayboudi <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222222944">(Jan 10 2021 at 13:45)</a>:</h4>
<p><span class="user-mention" data-user-id="220273">@Jane Lusby</span> I see your video "RustConf 2020 - Error handling Isn't All About Errors by Jane Lusby" and it is awesome. I have a lot of extra code regarding error handling. So I use anyhow for those that are not important like bootstrap the services, thiserror for important ones and based on error sending a message to user plus log with opentelemetry and tracing.</p>
<p>I have a lot of duplicated code <code>rust .await.map_err(|err| { tracing::error!("{:?}", err); err })?;</code></p>
<p>I am thinking I may reduce it with tracing-error. I find these examples and I couldn't find a correct way to use them with thiserror.<br>
<a href="https://github.com/tokio-rs/tracing/blob/master/examples/examples/custom-error.rs">https://github.com/tokio-rs/tracing/blob/master/examples/examples/custom-error.rs</a><br>
<a href="https://github.com/tokio-rs/tracing/blob/master/examples/examples/instrumented-error.rs">https://github.com/tokio-rs/tracing/blob/master/examples/examples/instrumented-error.rs</a><br>
<a href="https://github.com/tokio-rs/tracing/blob/master/examples/examples/map-traced-error.rs">https://github.com/tokio-rs/tracing/blob/master/examples/examples/map-traced-error.rs</a></p>
<p>1st do you think I am on the right path and I should remove map_error?<br>
2nd tracing-error is a right solution for mine?</p>
<p>I post this question on discord/tokio/tracing as well so other people can use your guidance.</p>



<a name="222224643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222224643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hossein Mayboudi <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222224643">(Jan 10 2021 at 14:29)</a>:</h4>
<p><span class="user-mention" data-user-id="220273">@Jane Lusby</span> What is wrong with this code which it need err.into() instead of returning err?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">use</span><span class="w"> </span><span class="n">fip_common</span>::<span class="n">common_error</span>::<span class="n">CommonError</span><span class="p">;</span><span class="w"></span>
<span class="k">use</span><span class="w"> </span><span class="n">tonic</span>::<span class="n">Request</span><span class="p">;</span><span class="w"></span>

<span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">Sub</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">sub</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">request</span>: <span class="kp">&amp;</span><span class="nc">Request</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;&amp;</span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="n">CommonError</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">request</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">metadata</span><span class="p">()</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s">"sub"</span><span class="p">)</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">unwrap</span><span class="p">()</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">to_str</span><span class="p">()</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">map_err</span><span class="p">(</span><span class="o">|</span><span class="n">err</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="n">tracing</span>::<span class="n">error</span><span class="o">!</span><span class="p">(</span><span class="s">"{:?}"</span><span class="p">,</span><span class="w"> </span><span class="n">err</span><span class="p">);</span><span class="w"></span>
<span class="w">                </span><span class="n">err</span><span class="p">.</span><span class="n">into</span><span class="p">()</span><span class="w"></span>
<span class="w">            </span><span class="p">})</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[derive(Debug, thiserror::Error)]</span><span class="w"></span>
<span class="cp">#[non_exhaustive]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">enum</span> <span class="nc">CommonError</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="cp">#[error(transparent)]</span><span class="w"></span>
<span class="w">    </span><span class="n">TonicMetadataToStrError</span><span class="p">(</span><span class="cp">#[from]</span><span class="w"> </span><span class="n">tonic</span>::<span class="n">metadata</span>::<span class="n">errors</span>::<span class="n">ToStrError</span><span class="p">),</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="nb">From</span><span class="o">&lt;</span><span class="n">CommonError</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">tonic</span>::<span class="n">Status</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">from</span><span class="p">(</span><span class="n">common_error</span>: <span class="nc">CommonError</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">tonic</span>::<span class="n">Status</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">match</span><span class="w"> </span><span class="n">common_error</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">CommonError</span>::<span class="n">TonicMetadataToStrError</span><span class="p">(</span><span class="n">err</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="n">tonic</span>::<span class="n">Status</span>::<span class="n">unavailable</span><span class="p">(</span><span class="fm">format!</span><span class="p">(</span><span class="s">"{:?}"</span><span class="p">,</span><span class="w"> </span><span class="n">err</span><span class="p">))</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="222374032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222374032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222374032">(Jan 11 2021 at 23:43)</a>:</h4>
<p><span class="user-mention" data-user-id="378207">@Hossein Mayboudi</span> happy to help, first, are you using <a href="https://docs.rs/tracing-error/0.1.2/tracing_error/struct.TracedError.html">https://docs.rs/tracing-error/0.1.2/tracing_error/struct.TracedError.html</a> rn?</p>



<a name="222374051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222374051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222374051">(Jan 11 2021 at 23:43)</a>:</h4>
<p>or are you just using <code>SpanTrace</code></p>



<a name="222374195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222374195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222374195">(Jan 11 2021 at 23:45)</a>:</h4>
<p>the <code>Into</code> there is necessary because you didn't use <code>?</code></p>



<a name="222374199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222374199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222374199">(Jan 11 2021 at 23:45)</a>:</h4>
<p>which would call <code>Into</code> for you</p>



<a name="222417233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222417233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hossein Mayboudi <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222417233">(Jan 12 2021 at 11:11)</a>:</h4>
<p><span class="user-mention silent" data-user-id="220273">Jane Lusby</span> Since I want to use stable instead of night build of rust I have to use SpanTrace.</p>



<a name="222417478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222417478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hossein Mayboudi <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222417478">(Jan 12 2021 at 11:14)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">use</span><span class="w"> </span><span class="n">fip_common</span>::<span class="n">common_error</span>::<span class="n">CommonError</span><span class="p">;</span><span class="w"></span>
<span class="k">use</span><span class="w"> </span><span class="n">tonic</span>::<span class="n">Request</span><span class="p">;</span><span class="w"></span>

<span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">Sub</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">sub</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">request</span>: <span class="kp">&amp;</span><span class="nc">Request</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;&amp;</span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="n">CommonError</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">request</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">metadata</span><span class="p">()</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s">"sub"</span><span class="p">)</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">unwrap</span><span class="p">()</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">to_str</span><span class="p">()</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">map_err</span><span class="p">(</span><span class="o">|</span><span class="n">err</span><span class="o">|</span><span class="w"> </span>-&gt; <span class="nc">CommonError</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="n">tracing</span>::<span class="n">error</span><span class="o">!</span><span class="p">(</span><span class="s">"{:?}"</span><span class="p">,</span><span class="w"> </span><span class="n">err</span><span class="p">);</span><span class="w"></span>
<span class="w">                </span><span class="n">err</span><span class="w"> </span><span class="c1">// ERROR HERE</span>
<span class="w">            </span><span class="p">})</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>I get error [ERROR HERE],</p>
<div class="codehilite"><pre><span></span><code>mismatched types

expected enum `fip_common::common_error::CommonError`, found struct `tonic::metadata::errors::ToStrError`

help: try using a variant of the expected enum: `fip_common::common_error::CommonError::TonicMetadataToStrError(err)`rustc(E0308)
sub.rs(13, 17): expected enum `fip_common::common_error::CommonError`, found struct `tonic::metadata::errors::ToStrError`
</code></pre></div>



<a name="222417680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222417680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hossein Mayboudi <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222417680">(Jan 12 2021 at 11:16)</a>:</h4>
<p>if I use <code>?</code> how should I capture an error <code>tracing::error!("{:?}", err);</code>?</p>



<a name="222418683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222418683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hossein Mayboudi <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222418683">(Jan 12 2021 at 11:28)</a>:</h4>
<p>More importantly, how can I remove all map_err in my code by just using <code>?</code>, with respect to if an error happens, tracing log it on the pipeline so everything which connects to the pipeline act accordingly.</p>
<p>I think if I have to use tracing-error/SpanTrace, my above statement is not possible since in map_err I have to call SpanTrace::capture().</p>



<a name="222453769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222453769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hossein Mayboudi <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222453769">(Jan 12 2021 at 16:13)</a>:</h4>
<p>I solve it:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[derive(Debug)]</span><span class="w"></span>
<span class="cp">#[non_exhaustive]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">CommonError</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">common_error_kind</span>: <span class="nc">CommonErrorKind</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">span_trace</span>: <span class="nc">tracing_error</span>::<span class="n">SpanTrace</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="cp">#[derive(Debug, thiserror::Error)]</span><span class="w"></span>
<span class="cp">#[non_exhaustive]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">enum</span> <span class="nc">CommonErrorKind</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="cp">#[error(transparent)]</span><span class="w"></span>
<span class="w">    </span><span class="n">TonicMetadataToStrError</span><span class="p">(</span><span class="cp">#[from]</span><span class="w"> </span><span class="n">tonic</span>::<span class="n">metadata</span>::<span class="n">errors</span>::<span class="n">ToStrError</span><span class="p">),</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="nb">From</span><span class="o">&lt;</span><span class="n">CommonError</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">tonic</span>::<span class="n">Status</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">from</span><span class="p">(</span><span class="n">common_error</span>: <span class="nc">CommonError</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">tonic</span>::<span class="n">Status</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">match</span><span class="w"> </span><span class="n">common_error</span><span class="p">.</span><span class="n">common_error_kind</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">CommonErrorKind</span>::<span class="n">TonicMetadataToStrError</span><span class="p">(</span><span class="n">err</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="n">tonic</span>::<span class="n">Status</span>::<span class="n">unavailable</span><span class="p">(</span><span class="fm">format!</span><span class="p">(</span><span class="s">"{:?}"</span><span class="p">,</span><span class="w"> </span><span class="n">err</span><span class="p">))</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">E</span><span class="o">&gt;</span><span class="w"> </span><span class="nb">From</span><span class="o">&lt;</span><span class="n">E</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">CommonError</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="n">CommonErrorKind</span>: <span class="nb">From</span><span class="o">&lt;</span><span class="n">E</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">from</span><span class="p">(</span><span class="n">source</span>: <span class="nc">E</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="bp">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">common_error_kind</span>: <span class="nc">CommonErrorKind</span>::<span class="n">from</span><span class="p">(</span><span class="n">source</span><span class="p">).</span><span class="n">into</span><span class="p">(),</span><span class="w"></span>
<span class="w">            </span><span class="n">span_trace</span>: <span class="nc">tracing_error</span>::<span class="n">SpanTrace</span>::<span class="n">capture</span><span class="p">(),</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">std</span>::<span class="n">fmt</span>::<span class="n">Display</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">CommonError</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">fmt</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">f</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">std</span>::<span class="n">fmt</span>::<span class="n">Formatter</span><span class="o">&lt;'</span><span class="nb">_</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">std</span>::<span class="n">fmt</span>::<span class="nb">Result</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="fm">write!</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="w"> </span><span class="s">"({:?} =&gt; {:?})"</span><span class="p">,</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">span_trace</span><span class="p">,</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">common_error_kind</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="222457472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222457472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hossein Mayboudi <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222457472">(Jan 12 2021 at 16:36)</a>:</h4>
<p>.</p>



<a name="222480356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222480356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222480356">(Jan 12 2021 at 19:14)</a>:</h4>
<p><span class="user-mention silent" data-user-id="378207">Hossein Mayboudi</span> <a href="#narrow/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts/near/222417680">said</a>:</p>
<blockquote>
<p>if I use <code>?</code> how should I capture an error <code>tracing::error!("{:?}", err);</code>?</p>
</blockquote>
<p>well, first of all, <code>tracing::error!</code> is a tracing error event, and is part of a logging system. That's not something that comes from <code>tracing-error</code>, it's part of <code>tracing</code> itself.</p>



<a name="222480362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222480362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222480362">(Jan 12 2021 at 19:14)</a>:</h4>
<p>so you cannot capture one of those</p>



<a name="222480369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222480369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222480369">(Jan 12 2021 at 19:14)</a>:</h4>
<p>that just emits a log event to your logger</p>



<a name="222480559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222480559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222480559">(Jan 12 2021 at 19:16)</a>:</h4>
<p>also that solution looks perfect</p>



<a name="222480654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222480654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222480654">(Jan 12 2021 at 19:16)</a>:</h4>
<p>presumably you then use that with <code>?</code> to avoid the explicit into call like this</p>



<a name="222480696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222480696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222480696">(Jan 12 2021 at 19:17)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">Sub</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">sub</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">request</span>: <span class="kp">&amp;</span><span class="nc">Request</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;&amp;</span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="n">CommonError</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">sub</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">request</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">metadata</span><span class="p">()</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s">"sub"</span><span class="p">)</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">unwrap</span><span class="p">()</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">to_str</span><span class="p">()</span><span class="o">?</span><span class="p">;</span><span class="w"></span>

<span class="w">        </span><span class="nb">Ok</span><span class="p">(</span><span class="n">sub</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="222480870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222480870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222480870">(Jan 12 2021 at 19:18)</a>:</h4>
<p>though you might still want to add some extra logic to still invoke <code>tracing::error!</code> if logging errors before you propagate them is important to you</p>



<a name="222480882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222480882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222480882">(Jan 12 2021 at 19:18)</a>:</h4>
<p>though I generally find myself doing one or the other, but not both</p>



<a name="222480901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Error%20context%2C%20with_context%2C%20and%20common%20contexts/near/222480901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Error.20context.2C.20with_context.2C.20and.20common.20contexts.html#222480901">(Jan 12 2021 at 19:18)</a>:</h4>
<p>as in, you either propagate, react to, or report an error</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>